package com.qiaofang.collectmanage.facade.impl;

import com.qiaofang.collectmanage.service.MergeRegionService;
import com.qiaofang.collectmanage.stub.constants.MergeRegionResponseCode;
import com.qiaofang.collectmanage.stub.facade.MergeRegionFacade;
import com.qiaofang.collectmanage.stub.request.MergeRegionRequest;
import com.qiaofang.collectmanage.stub.response.MergeRegionResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
public class MergeRegionFacadeImpl implements MergeRegionFacade {

    private static Logger logger = LoggerFactory.getLogger(MergeRegionFacadeImpl.class);

    @Autowired
    private MergeRegionService mergeRegionService;

    @Override
    public MergeRegionResponse mergeRegion(@RequestBody @Valid MergeRegionRequest request) {
        MergeRegionResponse response  =   new MergeRegionResponse();
        try {
            mergeRegionService.mergeRegion(request.getMergeRegionDTO());
        }catch (Exception e){
            response.setResponseCode(MergeRegionResponseCode.RC_MERGEREGION_ERROR.getResponseCode());
            response.setResponseMessage(MergeRegionResponseCode.RC_MERGEREGION_ERROR.getResponseMessage());
            logger.error("合并区域错误{}",e);
        }
        return  response;
    }
}
